package tests.delete;

import static org.junit.Assert.*;

import java.net.UnknownHostException;

import model.Budget;
import model.BudgetFactory;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.workplicity.util.Helper;
import org.workplicity.worklet.WorkletContext;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

public class BudgetDeleteTest01
{
	Budget budget;
	BudgetFactory factory;

	@Before
	public void setUp() throws Exception
	{
	}

	@After
	public void tearDown() throws Exception
	{
		//Helper.delete(budget, WorkletContext.getInstance());
	}

	@Test
	public void test()
	{
		factory = new BudgetFactory();

		try
		{
			for (int i = 1; i <= 10; i++)
			{
				// Create a budget
				budget = (Budget) factory.create();
				budget.setName("Test budget " + i);

				budget.setDescription("This is delete test budget " + i);

				budget.commit();

				Mongo mongo = null;
		  		try
		  		{
		  			mongo = new Mongo();
		  		} catch (UnknownHostException e)
		  		{
		  			// TODO Auto-generated catch block
		  			e.printStackTrace();
		  		} catch (MongoException e)
		  		{
		  			// TODO Auto-generated catch block
		  			e.printStackTrace();
		  		}
		  		
		          DB db = mongo.getDB("cc");
		          DBCollection collection = db.getCollection(budget.getRepositoryName());
		          collection.remove(new BasicDBObject("entry.id", budget.getId()));
		          
		          collection = db.getCollection("Lines");//line.getRepositoryName());
		          collection.remove(new BasicDBObject("entry.id", budget.getId()));

				
			}

		} catch (Exception e)
		{
			fail("Creating Budget failed with exception: " + e);
		}
	}

}
